<template>
  <PageListContainer>
    <div class="base-block">
      <k-search :model="state.params" @search="methods.onSearch" @reset="onClickReset">
        <el-form-item label="代理搜索">
          <el-input v-model="state.params.keyword" clearable placeholder="请输入代理账号名、手机号" style="width: 250px;" />
        </el-form-item>
        <el-form-item label="打款状态">
          <el-select v-model="state.params.status" placeholder="不限">
            <el-option
              v-for="item in statusOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="申请时间">
          <el-date-picker
            v-model="state.params._timeArr"
            type="daterange"
            format="YYYY-MM-DD"
            value-format="YYYYMMDD"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :shortcuts="dateShortcut"
            @change="timeChange"
          />
        </el-form-item>
      </k-search>
    </div>
    <div class="base-block">
      <KToolbar>
        <template #right>
          <el-button type="default" :icon="Download" @click="onClickExportData">导出数据</el-button>
        </template>
      </KToolbar>

      <KTable v-loading="state.loading" v-bind="tableState" v-on="tableEvent">
        <template #remittance="s">
          <div>用户：{{ s.row.bank_account }}</div>
          <div>开户行：{{ s.row.bank_name }}</div>
          <div>银行卡号：{{ s.row.bank_no }}</div>
        </template>

        <template #actions="s">
          <el-link v-if="s.row.status === 0" type="primary" @click="onClickExamine(s.row)">待审核</el-link>
          <el-link v-else-if="s.row.status === 2" type="warning" @click="onClickExamine(s.row)">申请驳回</el-link>
          <el-link v-else-if="s.row.status === 1" type="primary" @click="onClickExamine(s.row)">已打款</el-link>
        </template>
      </KTable>
    </div>
    <!-- 代理结算审核 -->
    <ExamineModal ref="examineModal" @success="methods.onSearch" />
  </PageListContainer>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue';
import { Download } from '@element-plus/icons-vue';
import { useTableList, statusOptions } from './hooks/use-table';
import { cashListExport } from '@/api/crm-agency/download';
import ExamineModal from './components/examine-modal.vue';
import { toolGetDateRangeShorcuts as dateShortcut } from '@/utils';

defineOptions({ name: 'AgencyDyjAgentRemitList' });
const { state, tableState, tableEvent, ...methods } = useTableList({});

const onClickExportData = () => {
  cashListExport(methods.getParams(state.params).data);
};

// 审批
const examineModal = ref();
const onClickExamine = (row: any) => {
  examineModal.value.show(1, row);
};
// 重置
const onClickReset =() => {
  methods.onReset();
  timeArr.value = [];
};
/**
 * @时间控件
 */
const timeArr = ref([]);
const timeChange = () => {
  methods.onSearch();
};
</script>
